<template>
	<view class="">
		<view class="">
			<!-- 2.0.19支持autoBack，默认为false -->
			<u-navbar leftText="我的转发" autoBack>
			</u-navbar>
		</view>


		<view class="con-body wrap">
			<view style="height: 20rpx;"></view>
			<view class="u-demo-block__content">
				<view class="album" v-for="(item, index) in releases">
					<view class="album__avatar">
						<u-avatar :src="item.avatar" mode="circle">
						</u-avatar>
					</view>
					<view class="album__content">
						<u-text :text="item.username" color="#3e3e3e" bold size="17"></u-text>
						<u-text margin="0 0 8rpx 0" color="#999999" size="14" :text="'来自 ' + item.from"></u-text>
						<text style="color: #0B898E; font-size: 28rpx;">{{item.theme}}</text>
						<text style="color: #333333;font-size: 30rpx;margin-left: 10rpx;"> {{item.content}}</text>

						<view style="margin-top: 20rpx; margin-bottom: 10rpx;">
							<u-album :urls="item.images" multipleSize="90" space="4"></u-album>
						</view>

						<view>
							<text style="color: #666666; font-size: 26rpx; float: left;">{{item.time}}</text>
						
							<view style="margin-right: 10rpx; float: right; display: inline;">
								<u-icon @click="intoComment(item)" name="chat-fill" size="18" label-size="26rpx"
									color="#999" :label="item.comment + '评论'"></u-icon>
							</view>
							<view style="margin-right: 10rpx; float: right; display: inline;">
								<u-icon name="heart" size="18" color="#999" label-size="26rpx"
									:label="item.like + '赞'" @click="like(item.id, index)"></u-icon>
							</view>
							<view style="margin-right: 10rpx; float: right; display: inline;">
								<u-icon name="eye" size="18" color="#999" label-size="26rpx"
									:label="item.see + '浏览'"></u-icon>
							</view>
						
						</view>
					</view>
				</view>
				<u-toast ref="uToast"></u-toast>
				<u-empty :show="showEmpty" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
				</u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyForward,
		likeDynamic,
	} from "@/service/communitService.js";
	export default {
		data() {
			return {
				albumWidth: 0,
				showEmpty:false,
				releases: [],
				reFresh: "",
			}
		},
		onLoad() {
			getMyForward().then(this.getMyForward);
		},
		watch:{
			//监听reFresh,如果有修改就执行监听器
				reFresh: function() {
					this.releases=[];
			        //调接口刷新数据
					getMyForward().then(this.getMyForward);
				}
		},
		methods:{
			getMyForward(e) {
				if (e.code == 200) {
					this.showEmpty = false;
					let list = e.result;
					list.forEach(item => {
						this.releases.push(item);
					})
				} else {
					this.status = 'nomore';
					this.releases=[]
					if (this.releases.length == 0) {
						this.showEmpty = true;
					}
				}
			},
			like(id, index) {
				likeDynamic({
					gid: id
				}).then(res => {
					if (res.code == 200) {
						this.releases[index].like += 1;
						this.$refs.uToast.show({
							type: 'success',
							title: '成功',
							message: res.msg
						})
					} else {
						this.$refs.uToast.show({
							type: 'error',
							title: '失败',
							message: res.msg
						})
					}
				});
			},
			intoComment(item) {
				this.$u.route({
					url: '/pagesCommunity/index/comment',
					params: {
						id: item.id
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.wrap {
		width: 96%;
		margin-left: 2%;
	}

	.album {
		@include flex;
		padding: 20rpx;
		margin-top: 1px;
		margin-bottom: 20rpx;
		align-items: flex-start;
		background-color: #FFFFFF;
		border-radius: 10rpx;


		&__avatar {
			padding: 5rpx;
			border-radius: 3rpx;
		}

		&__content {
			margin-left: 20rpx;
			flex: 1;
		}
	}
</style>
